import { ref } from 'vue'
import { updateCheckFlowTemplateWithProcess } from '@/api/basic'

/**
 * 自定义审批流模板和流程表单服务
 */
export default function () {
  const checkFlowTemplateWithProcessFormSaveLoading = ref(false)
  const checkFlowTemplateWithProcessForm = ref<BaseInfoAPIRequest.CheckFlowTemplateWithProcessForm>(
    {
      flowTemplateEntity: {
        code: '',
        description: '',
        gmtCreate: '',
        gmtUpdate: '',
        id: '',
        name: '',
      },
      flowTemplateNodeRelationList: [],
    },
  )

  const resetCheckFlowTemplateWithProcessForm = () => {
    checkFlowTemplateWithProcessForm.value = {
      flowTemplateEntity: {
        code: '',
        description: '',
        gmtCreate: '',
        gmtUpdate: '',
        id: '',
        name: '',
      },
      flowTemplateNodeRelationList: [],
    }
  }

  const checkFlowTemplateWithProcessFormSave = async () => {
    try {
      checkFlowTemplateWithProcessFormSaveLoading.value = true
      const res = await updateCheckFlowTemplateWithProcess(checkFlowTemplateWithProcessForm.value)
      checkFlowTemplateWithProcessFormSaveLoading.value = false
      return res.data
    } catch (e) {
      checkFlowTemplateWithProcessFormSaveLoading.value = false
    }
  }

  return {
    checkFlowTemplateWithProcessForm,
    checkFlowTemplateWithProcessFormSaveLoading,
    checkFlowTemplateWithProcessFormSave,
    resetCheckFlowTemplateWithProcessForm,
  }
}
